// 递归处理数据格式
export function formatData(data, config = {}) {
  const format = [];
  const level = config && config.level || 0;
  const childrenKey = config && config.childrenKey || 'children';
  if (data && data.length) {
    data.forEach(v => {
      // 没有子项不默认赋值[]
      const children = v[childrenKey] && v[childrenKey].length && formatData(v[childrenKey], { ...config, level: level + 1 });
      format.push({
        ...v,
        value: v[config.value || 'id'],
        label: v[config.label || 'name'],
        disabled: v[config.disabled || 'status'] === 0,
        level: level,
        children
      })
    })
  }
  return format
}
// 获取数组指定元素下标
export function getArrayIndex(list, id) {
  for (let i = 0; i < list.length; i++) {
    if (list[i] === id) {
      return i
    }
  }
}
